<template>
  <div>
    <div class="action-bar">
      <el-button type="primary" size="mini" icon="el-icon-plus" @click="selectProperty">选择属性</el-button>
    </div>
    <SelectDialog title="选择属性" :append-to-body="true" :show="propertyDialogFormVisible" @on-ok="selectPropertyOk" @on-cancel="selectPropertyCancel">
      <Property ref="propertyInstance" :multiple-selected="true" :for-selection="true" :instance-id="instanceId" />
    </SelectDialog>
  </div>
</template>
<script>
import Property from '@neu/dcom-ui/views/workOrder/forms/change/attrForm'
import SelectDialog from '@neu/biz-core/components/SelectDialog'
import { deepClone } from '@neu/biz-core/utils'

export default {
  name: 'ChangeCiPropertyActionBar',
  components: {
    Property,
    SelectDialog
  },
  props: {
    instanceId: {
      required: true,
      type: String
    }
  },
  data() {
    return {
      uploadDialogFormVisible: false,
      dialogFormVisible: false,
      propertyDialogFormVisible: false
    }
  },
  methods: {
    // 新建用户按钮点击处理
    add() {
      this.dialogFormVisible = true
    },
    selectProperty() {
      this.propertyDialogFormVisible = true
    },
    // 创建用户对话框确认事件处理
    ok() {
      // 直接调用表单实例的保存方法
      this.$refs.editForm.save().then(response => {
        if (response === false) return
        this.$message({
          showClose: true,
          message: '操作成功！',
          type: 'success'
        })
        // 关闭对话框
        this.dialogFormVisible = false
        this.$refs.editForm.reset()
      })
    },
    cancel() {
      this.$refs.editForm.reset()
      this.dialogFormVisible = false
    },
    handleSuccess(response) {
      this.uploadDialogFormVisible = false
      this.$parent.refresh()
    },
    closeDialog() {
      this.uploadDialogFormVisible = false
      this.$parent.refresh()
    },
    selectPropertyOk() {
      const selections = this.$refs.propertyInstance.selections
      const data = deepClone(selections)

      this.$emit('addRow', data)

      this.propertyDialogFormVisible = false
    },
    selectPropertyCancel() {
      this.propertyDialogFormVisible = false
    }
  }

}
</script>
